package org.ccpp.portal.sql;

import java.sql.ResultSet;
import java.sql.Statement;

public class SQLSentenciasDDL extends SQLBasico{

	public boolean funcionaConsulta(String sql){
		boolean bExiste=true;
		ResultSet rs=null;
		try{
			rs=getStatement().executeQuery(sql);
		}catch(Exception e2){
			bExiste=false;
		}finally{
			try{
				rs.close();
			}catch(Exception e){}
		}
		return bExiste;
	}
	
	public void crearTablaSiExiste(String sTabla, String sCampos){
		try{
			super.conectar();
			String sql="select 1 from " + sTabla + " where 1=0";
			if (funcionaConsulta(sql) == false){
				sql="create table " + sTabla + "(" + sCampos + ")";
				System.out.println(sql);
				getStatement().execute(sql);
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			super.desconectar();
		}
	}
	
}
